package app.android.com.wuandroidapp.test.model.http;

import android.util.Log;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import app.android.com.wuandroidapp.library.util.OkHttp3Utils;
import app.android.com.wuandroidapp.test.model.db.entities.minimalist.Data;
import app.android.com.wuandroidapp.test.model.db.entities.minimalist.FaceMapModel;
import app.android.com.wuandroidapp.test.model.db.entities.minimalist.HelpPromodtionDetail;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.RequestBody;
import okhttp3.Response;

/**
 * @author wjw
 *         Created by admin on 2017/4/22.
 */

public class HttpService {

    public static void getStpromotion(OKCallBack callBack) {
        String url = "http://192.168.11.48:8080/CC-Chat/api/v1.0/helpIt/promotion/detail";
        RequestBody formBody = new FormBody.Builder()
                .add("taskid", "26")
                .add("accessToken", "YB016e2020ba59187c91f141e35e7fc0bf5513053bba59187c91f141e35e7fc0bf5513053b5d6a0a5f21e5809dd1f9229f45784ecfFDYB")
                .build();
        Call call = OkHttp3Utils.getInstance().postAsynHttp(formBody, url);
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                Log.e("wangshu", e.getMessage());
                callBack.onError(e.getMessage());
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                String str = response.body().string();
                Gson gson = new Gson();
                //gson泛型
                Data apResult = gson.fromJson(str, new TypeToken<Data<HelpPromodtionDetail>>() {
                }.getType());
                Log.e("gsontojson", gson.toJson(apResult));
             //   HelpPromodtionDetail re = (HelpPromodtionDetail) apResult.data;
                Log.e("wangshu", str);
                callBack.onSuccess(apResult);
            }

        });
    }

    public static void getctity(OKCallBack callBack) {
        String url = "";

        Call call = OkHttp3Utils.getInstance().getAsynHttp(url);
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                Log.e("wangshu", e.getMessage());
                callBack.onError(e.getMessage());
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                String str = response.body().string();
                Log.e("wangshu", str);
            }

        });
    }

    public static void getBD() {
        String url = "http://www.baidu.com";
        Call call = OkHttp3Utils.getInstance().getAsynHttp(url);
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                Log.e("wangshu", e.getMessage());
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                String str = response.body().string();
                Log.e("wangshu", str);
            }

        });
    }

    /**
     * 地图 查询
     * /helpIt/face/map	选取标签: label(非必填)
     * 地图深度: depth (默认1 最大值5 越大查询范围越大)
     * 定位所在城市: city
     * 定位纬度:la
     * 定位经度:lo
     *
     * @param label
     * @param city
     * @param depth
     * @param place_la
     * @param place_lo
     * @param callBack
     */
    public synchronized static void sethelpItFaceMap(String depth, String city, String place_la, String place_lo, OKCallBack callBack) {

        String url = "http://192.168.11.48:8080/CC-Chat/api/v1.0/helpIt/face/map";
        RequestBody formBody = new FormBody.Builder()
                .add("city", city)
                .add("depth", place_la)
                .add("lo", place_lo)

                .add("accessToken", "YB016e2020ba59187c91f141e35e7fc0bf5513053bba59187c91f141e35e7fc0bf5513053b5d6a0a5f21e5809dd1f9229f45784ecfFDYB")
                .build();
        Call call = OkHttp3Utils.getInstance().postAsynHttp(formBody, url);
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                Log.e("wangshu", e.getMessage());
                callBack.onError(e.getMessage());
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                String str = response.body().string();
                Gson gson = new Gson();
                //gson泛型
                Data apResult = gson.fromJson(str, new TypeToken<Data<FaceMapModel>>() {
                }.getType());
                Log.e("gsontojson", gson.toJson(apResult));
//                    FaceMapModel re= (FaceMapModel) apResult.data;
                Log.e("wangshu", str);
                callBack.onSuccess(apResult);
            }

        });

    }
}
